package com.viethp.mt.customactivities;

import java.util.ArrayList;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.viethp.mt.activities.AGroupList;
import com.viethp.mt.activities.R;

public class ATabNearByGroup extends ActivityGroup {
	public static ATabNearByGroup group;
	private static ArrayList<View> arrList, callBack;
	private int count = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		arrList = new ArrayList<View>();
		callBack = new ArrayList<View>();
		group = this;

		View view = getLocalActivityManager().startActivity(
				"AGroupList",
				new Intent(this, AGroupList.class)
						.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
				.getDecorView();

		replaceView(view);

	}

	public void replaceView(View view) {
		Animation hyperspaceJump = AnimationUtils.loadAnimation(this,
				R.anim.slide_left_to_right_in);
		view.startAnimation(hyperspaceJump);

		arrList.add(view);
		setContentView(view);
		count++;
	}

	public void back() {
		if (arrList.size() > 1) {
			// View callback = arrList.get(arrList.size() - 1);
			// callBack.add(callback);
			arrList.remove(arrList.size() - 1);
			View v = arrList.get(arrList.size() - 1);
			Animation hyperspaceJump = AnimationUtils.loadAnimation(this,
					R.anim.slide_right_to_left_in);
			v.startAnimation(hyperspaceJump);
			setContentView(v);
			count--;
		} else {
			this.finish();
		}
	}

	public void callbackView() {
		if (callBack.size() > 0) {
			// callBack.remove(callBack.size()-1);
			View callback = callBack.get(arrList.size() - 1);
			arrList.add(callback);
			callBack.remove(callBack.size() - 1);
			Animation hyperspaceJump = AnimationUtils.loadAnimation(this,
					R.anim.slide_right_to_left_in);
			callback.startAnimation(hyperspaceJump);
			setContentView(callback);
		}
	}

	@Override
	public void onBackPressed() {
		ATabNearByGroup.group.back();
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getCount() {
		return this.count;
	}

	public int getcallbackSize() {
		return callBack.size();
	}
}
